﻿using BenchmarkDotNet.Attributes;
using Microsoft.Extensions.Caching.Memory;
using System.Collections.Generic;

namespace Puppy.Caching
{
    [MemoryDiagnoser]
    public class CachingBenchmark
    {
        private MemoryCache _memoryCache;
        private Dictionary<int, int> _dicCache;

        [Benchmark]
        [Arguments(100)]
        [Arguments(1000)]
        [Arguments(10000)]
        public void MemoryCache(int count)
        {
            _memoryCache.Set(count, count);
        }

        [Benchmark]
        [Arguments(100)]
        [Arguments(1000)]
        [Arguments(10000)]
        public void DictionaryCache(int count)
        {
            if(!_dicCache.ContainsKey(count))
                _dicCache.Add(count, count);
        }

        [GlobalSetup]
        public void Setup()
        {
            _memoryCache = new MemoryCache(new MemoryCacheOptions());
            _dicCache = new Dictionary<int, int>();
        }
    }
}
